package com.hue.gulimail.gulimailproduct.controller;

import java.util.Arrays;
import java.util.Map;

import com.hue.gulimail.gulimailproduct.vo.AttrResVo;
import com.hue.gulimail.gulimailproduct.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.hue.gulimail.gulimailproduct.service.AttrService;
import com.hue.common.utils.PageUtils;
import com.hue.common.utils.R;


/**
 * 商品属性
 *
 * @author yaofengqiao
 * @email 451737523@qq.com
 * @date 2021-08-12 16:24:48
 */
@RestController
@RequestMapping("gulimailproduct/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 获取销售属性
     */
    @RequestMapping("/sale/list/{catId}")
    //@RequiresPermissions("gulimailproduct:attr:list")
    public R list(@PathVariable("catId") Long catId, @RequestParam Map<String, Object> params) {
        PageUtils page = attrService.queryByCatId(catId,params,0);
        return R.ok().put("page", page);
    }

    /**
     * 获取基本属性
     */
    @RequestMapping("/base/list/{catId}")
    //@RequiresPermissions("gulimailproduct:attr:list")
    public R baseList(@PathVariable("catId") Long catId, @RequestParam Map<String, Object> params) {
        PageUtils page = attrService.queryByCatId(catId,params,1);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("gulimailproduct:attr:info")
    public R info(@PathVariable("attrId") Long attrId) {
        AttrResVo attrResVo = attrService.getAttrInfo(attrId);

        return R.ok().put("attr", attrResVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("gulimailproduct:attr:save")
    public R save(@RequestBody AttrVo attrVo) {
        attrService.saveAttrAndGroup(attrVo);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("gulimailproduct:attr:update")
    public R update(@RequestBody AttrResVo attrResVo) {
        attrService.updateAttr(attrResVo);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("gulimailproduct:attr:delete")
    public R delete(@RequestBody Long[] attrIds) {
        attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
